<%--
 *  File:    OrgCopyEdit.jsp
 *  @Author: Kent Zhong 
 *  Date:    3/4/2005 10:07AM
 *
 *  Copyright (C) 2000 - 2005 Oval Technologies, Inc.
 *  All rights reserved. 
 *
 *  This software is the confidential and proprietary information of Oval 
 *  Technologies, Inc. ("Confidential Information").  You shall not
 *  disclose such Confidential Information and shall use it only in
 *  accordance with the terms of the license agreement you entered into
 *  with Oval.
--%>
 

<%@ include file="/inc/SessionTimeout.inc"%>
<%@ page language="java" %>     
<%@ page import="java.util.*" %>
<%@ page import="org.apache.log4j.Category" %>
<%@ page import="com.oval.util.*" %>

<%@ page contentType = "text/html;charset=UTF-8" %>
<%@ taglib uri="/WEB-INF/PageFlow.tld" prefix="PageFlow" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/custom.tld" prefix="custom" %>


<%
  	Category cat = Category.getInstance("jsp.OrgCopyEdit");  
%>

<%
	String strModuleName = "IMG";
	String privilegeCode = "Z0821";
  	
  	
%>


<%@ include file="/inc/Security.inc" %>
<%@ include file="/inc/FrmDefault.inc" %>
<%@ include file="/inc/PageDefault.inc" %>
<%@ include file="/inc/LocationDefault.inc" %>

<html>
<head>
<title>OrgCopyEdit</title>
<PageFlow:CheckPageFlow pageName="orgcopyedit"/>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="../css/<%= strLanguageCode %>/main.css" type="text/css">
<script language="JavaScript" src="../css/<%= strLanguageCode %>/script.js"></script>
<script language="JavaScript" src="../js/ScriptLib.js"></script>
<%
  String strIsNew=(String)pageContext.getAttribute("isnew");
  boolean isNew="Y".equals(strIsNew);
  boolean isUseSystem=false;
  boolean isAdmReadOnly=true;
  String strNullAble="nullable";
  String strNeed="td-text";
  if(pageContext.getAttribute("sourceorginfo")!=null )
  {
    HashMap hmSource=(HashMap)pageContext.getAttribute("sourceorginfo");
    if(hmSource.containsKey("solutiontype") && ("1".equals(hmSource.get("solutiontype").toString()) || "2".equals(hmSource.get("solutiontype").toString())))
    {
      isUseSystem=true;
      isAdmReadOnly=false;
      strNullAble="notnull";
      strNeed="need";
    }
  }
%>
<script>
function isAllEnglish(s)	//Is the string s all English? All English:return true.
{
	var i,c;
	for(i=0;i<s.length;i++)
	{
		c=s.charAt(i);
		if((c>="A"&&c<="Z")||(c>="a"&&c<="z")||c=="_"||(c>=0&&c<=9))
		{
			if(c==" ")
				return false;
			continue;
		}
		else
			return false;
	}
	return true;
}
function page_save()
{
  if(!checkForm(thisform)) return;
  <%if(isUseSystem){%>
  if(!isAllEnglish(thisform.adminname.value))
  {
    	alert("<%= message.getMessageDesc("ILLEGAL_FORMAT",label.getLabelName("L_AdmUserName",false)) %>");
    	return false;
  }  
  	
  if((thisform.adminname.value.length > 12)||(thisform.adminname.value.length < 4))
  {
    	alert("<%= message.getMessageDesc("LENGTH_MUST_BETWEEN",label.getLabelName("L_AdmUserName",false),"4", "12") %>");
    	return false;
  }
  if(thisform.adminpwd.value != thisform.adminpwdconfirm.value)
  {
    alert("<%= message.getMessageDesc("DIFFERENT_PASSWORD") %>");
    return ;
  } 
  if(thisform.adminpwd.value == thisform.adminname.value)
  {
    alert("<%= message.getMessageDesc("VALUE_MUST_NOTEQUAL",label.getLabelName("L_AdmPassword",false),label.getLabelName("L_AdmUserName",false)) %>");
    return ;
  } 
  var isnew = <%=JspHelper.filterNull( isNew )%>;
  if(isnew || (!isnew && !isEmpty(thisform.adminpwd.value)))
  {
    if((thisform.adminpwd.value.length > 16) || (thisform.adminpwd.value.length < 4))
    {
    	alert("<%= message.getMessageDesc("LENGTH_MUST_BETWEEN",label.getLabelName("L_AdmPassword",false),"4", "16") %>");
    	return;
    }	
    if(isCharsInBag(thisform.adminpwd.value,"0123456789"))
  	{
	  	alert("<%= message.getMessageDesc("VALUE_MUST_NOT_BE_ALL_NUMBER",label.getLabelName("L_AdmPassword",false)) %>");
		 	return;
	  }     
  }
  <%}%>
  if(isEmpty(thisform.parentorgcode.value))
  {
    if(!confirm("<%= message.getMessageDesc("CONFIRM_PARENT_ORG_IS_NULL") %>"))
        return;
    else
    {
      thisform.parentorgid.value=" "; 
    }    
  }
  
  //emptyToNull(thisform);
  thisform.actionname.value="save";
  thisform.target = "_parent";
  isRunning = true;
  thisform.submit();  
  
}
function page_orgselect(stype)
{
  thisform.selectorgtype.value=stype;
  var strUrl='../masterdata/ogm/OrgSelect.jsp?<%= OvalTools.randomURL() %>';
  var strStatus='height=250, width=600,top=100,left=100,toolbar=no, menubar=no, scrollbars=yes, resizable=no, location=no, status=no';
  popwindow=window.open(strUrl,'newwindow',strStatus);
}
function page_setOrg(id,name,code)
{
  var objid=eval("thisform."+thisform.selectorgtype.value+"orgid");
  var objcode=eval("thisform."+thisform.selectorgtype.value+"orgcode");
  var objname=eval("thisform."+thisform.selectorgtype.value+"orgname");
  objid.value=id;
  objcode.value=code;
  objname.value=name;
  page_orgchange(thisform.selectorgtype.value);
  
}
function page_orgchange(stype)
{
  var objid=eval("thisform."+stype+"orgid");
  var objcode=eval("thisform."+stype+"orgcode");
  var objname=eval("thisform."+stype+"orgname");
  objid.value="";
  objname.value="";
  if(!isEmpty(objcode.value))
  {
    thisform.reloadtype.value=stype;
    thisform.actionname.value="reload";
    thisform.target = "_self";
  	isRunning = true;
  	thisform.submit(); 
  }
}
</script>
</head>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0"  Scroll=no >
<form name="thisform" method="post" action="../Dispatcher"  target="_parent">
          <input type="hidden" name="pagename" value="orgcopyedit">
          <input type="hidden" name="actionname">
          <custom:hidden property="isnew"/>
          <custom:hidden property="orgcopyid"/>
          <input type="hidden" name="selectorgtype"/>
          <input type="hidden" name="reloadtype"/>
          <%if(isNew){%>
          <custom:hidden name="userinfo" property="userid"  changedName="maker" scope="session"/>
          <input type="hidden" name="status" value="10"/>
          <%}%>
<table id="topTable" border=0 cellpadding=0 cellspacing=0 width="100%">
  <tr> 
    <td valign=top>
        <table border=0 cellpadding=1 cellspacing=0 width="100%">
         
          <tbody> 
          <tr> 
            <td bgcolor=#000000 style="PADDING-BOTTOM: 1px; PADDING-LEFT: 1px; PADDING-RIGHT: 1px; PADDING-TOP: 0px"> 
              <table bgcolor=#000000 border=0 cellpadding=0 cellspacing=0 width="100%">
                <tr> 
                  <td  bgcolor=#ffffff style="PADDING-BOTTOM: 3px; PADDING-LEFT: 3px; PADDING-RIGHT: 3px; PADDING-TOP: 3px"> 
                   <div id=div2 style="HEIGHT: 245px; OVERFLOW: auto"> 
                      <table border="1" cellspacing="0" bordercolorlight="#999999" bordercolordark="#FFFFFF" align="center" width="100%" cellpadding="1">
                        <tr> 
                          <td colspan="4" class="td_right"> 
                            <a onclick="page_save();"><custom:button type="2" label="L_Save" imgsrc="save.gif" border="0" style="width:60"/></a>
                          </td>
                        </tr>
                        <%if(isNew){%>
                        <tr> 
                          <td class="need"><%=label.getLabelName("L_CopySourceOrg")+label.getLabelName("L_Colon")%></td> 
                          <td colspan="3">
                            <custom:hidden name="sourceorginfo" property="orgid" changedName="sourceorgid"/>
                            <custom:text name="sourceorginfo" command="notnull" label="L_CopySourceOrg" module="IMG" property="orgcode" changedName="sourceorgcode" size="15" onchange="page_orgchange('source');"/>
                            <a onclick="page_orgselect('source');"><custom:button type="3" label="L_Asterisk" imgsrc="flash.gif" border="0"/></a>
                            <custom:text name="sourceorginfo" property="orgname"  readonly="true" changedName="sourceorgname" size="45"/>
                          </td>
                        </tr>
                        <%}%>
                        <tr> 
                          <td width="107" class="need" height="20"><%=label.getLabelName("L_OrgCode")+label.getLabelName("L_Colon")%></td>
                          <td width="200"> 
                            <custom:text name="orgcopyinfo" property="orgcode"  command="notnull" label="L_OrgCode" module="IMG" size="25"/>
                          </td>
                          <td class="need" width="110" ><%=label.getLabelName("L_ShortName")+label.getLabelName("L_Colon")%></td>
                          <td> 
                            <custom:text name="orgcopyinfo" property="shortname"  command="notnull" label="L_ShortName" module="IMG" size="25"/>
                          </td>
                        </tr>
                        <tr> 
                          <td width="107" class="need" height="20"><%=label.getLabelName("L_OrgType")+label.getLabelName("L_Colon")%></td>
                          <td width="200"> 
                            <custom:select optionsName="orgtypelists"  name="orgcopyinfo" optionValueKey="saleschannelid"  command="notnull" label="L_OrgType" module="IMG" optionInnerTextKey="saleschannelname" property="orgtype" />
                          </td>
                          <td class="need" width="110" ><%=label.getLabelName("L_OrgName")+label.getLabelName("L_Colon")%></td>
                          <td> 
                            <custom:text name="orgcopyinfo" property="orgname"  command="notnull" label="L_OrgName" module="IMG" size="25"/>
                          </td>
                        </tr>
                        <tr> 
                          <td width="107" class="td-text" height="20"><%=label.getLabelName("L_ParentOrg")+label.getLabelName("L_Colon")%></td>
                          <td  colspan="3"> 
                            <custom:hidden name="orgcopyinfo" property="parentorgid" />
                            <custom:text name="orgcopyinfo" property="parentorgcode"  size="15"  onchange="page_orgchange('parent');"/>
                            <a onclick="page_orgselect('parent');"><custom:button type="3" label="L_Asterisk" imgsrc="flash.gif" border="0"/></a>
                            <custom:text name="orgcopyinfo" property="parentorgname"  readonly="true" size="45"/>
                          </td>
                        </tr>
                        <tr>  
                          <td class="need" width="110" ><%= label.getLabelName("L_OwnerOrg") + label.getLabelName("L_Colon") %></td>
                          <td  colspan="3"> 
                            <custom:hidden name="orgcopyinfo" property="ownerorgid" />
                            <custom:text name="orgcopyinfo" property="ownerorgcode"  command="notnull" label="L_OwnerOrg" module="IMG"  size="15"  onchange="page_orgchange('owner');"/>
                            <a onclick="page_orgselect('owner');"><custom:button type="3" label="L_Asterisk" imgsrc="flash.gif" border="0"/></a>
                            <custom:text name="orgcopyinfo" property="ownerorgname" readonly="true" size="45"/>
                          </td>
                        </tr>
                        <%if(isUseSystem){%>
                        <tr> 
                          <td width="107" class="<%=JspHelper.filterNull(strNeed)%>" height="20"><%= label.getLabelName("L_AdmUserName") + label.getLabelName("L_Colon") %></td>
                          <td width="200"> 
                            <custom:text name="orgcopyinfo" property="adminname"  readonly="<%=isAdmReadOnly%>" command="<%=strNullAble%>" label="L_AdmUserName" module="IMG" size="25"/>
                          </td>
                          </td>
                          <td class="<%=JspHelper.filterNull(strNeed)%>" width="110" ><%= label.getLabelName("L_AdmPassword") + label.getLabelName("L_Colon") %></td>
                          <td> 
                            <%if(isNew){%>
                            <input type="password" name="adminpwd"  command="<%=JspHelper.filterNull(strNullAble)%>"   <%=JspHelper.filterNull(isAdmReadOnly?"readonly":"")%> size="25" label="<%= message.getMessageDesc("VALUE_NOT_NULL", label.getLabelName("L_AdmPassword",false)) %>">              		
                            <%}else{%>
                            <input type="password" name="password0"   <%=JspHelper.filterNull(isAdmReadOnly?"readonly":"")%>  value="********" size="25" onblur="javascript:if(password0.value.indexOf('*')<0)adminpwd.value=password0.value;">              		
                            <input type="hidden" name="adminpwd">
                            <%}%>
                          </td>
                        </tr>
                        <tr> 
                          <td class="<%=JspHelper.filterNull(strNeed)%>" width="110" ><%= label.getLabelName("L_AdmPasswordConfirm") + label.getLabelName("L_Colon") %></td>
                          <td > 
                            <%if(isNew){%>
                            <input type="password" name="adminpwdconfirm"   <%=JspHelper.filterNull(isAdmReadOnly?"readonly":"")%> command="<%=JspHelper.filterNull(strNullAble)%>" size="25" label="<%= message.getMessageDesc("VALUE_NOT_NULL", label.getLabelName("L_AdmPasswordConfirm",false)) %>">              		
                            <%}else{%>
                            <input type="password" name="adminpwdconfirm0"   <%=JspHelper.filterNull(isAdmReadOnly?"readonly":"")%>  value="********" size="25" onblur="javascript:if(adminpwdconfirm0.value.indexOf('*')<0)adminpwdconfirm.value=adminpwdconfirm0.value;">              		
                            <input type="hidden" name="adminpwdconfirm">
                            <%}%>
                          </td>
                          <td  class="need" >&nbsp;</td>
                          <td>&nbsp;</td>
                        </tr>
                        <%}%>
                      </table>
                    </div>                 </td>
                </tr>
              </table>
            </td>
          </tr>
          </tbody> 
         
        </table>
    </td>
  </tr>
  <tr> 
    <td class=summary_top></td> 
  </tr>
  <%@include file="OrgCopyBtn.inc"%>
</table>
</form>
</body>
</html>
